<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/calendar.js"></script>
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var userCode = document.getElementById("userCode");
		var userName = document.getElementById("userName");
		var roleId = document.getElementById("roleId");
		var deptId = document.getElementById("deptId");
		var email = document.getElementById("email");
		
		var isPassword = document.getElementsByName("isPassword");
		var password = document.getElementById("password");
		var password2 = document.getElementById("password2");
		
		if(userCode.value == ""){
			alert("<fmt:message key='user.lable.userCode'/><fmt:message key='common.message.empty'/>");
			return false;
		}
		if(userName.value == ""){
			alert("<fmt:message key='user.lable.userName'/><fmt:message key='common.message.empty'/>");
			return false;
		}
		if(deptId.value == 0){
			alert("<fmt:message key='user.message.dept'/>");
			return false;
		}
		if(roleId.value == 0){
			alert("<fmt:message key='user.message.role'/>");
			return false;
		}
		
		if(email.value != ""){
			if(!isEmail(email)){
				alert("输入的Email格式不正确!");
				return false;
			}
		}
		
		if(isPassword[0].checked){
			if(password.value == ""){
				alert("<fmt:message key='user.lable.newPassword'/><fmt:message key='common.message.empty'/>");
				return false;
			}
			if(password2.value == ""){
				alert("<fmt:message key='user.lable.password2'/><fmt:message key='common.message.empty'/>");
				return false;
			}
			if(password.value != password2.value){
				alert("<fmt:message key='user.message.notPassword'/>");
				return false;
			}
		}
		return true;
	}

	function back(){
		window.location.href = "./user.do";
		window.location.target = "main";
	}
	
	function showHidden(id){
		var obj = document.getElementById(id);
		var objs = document.getElementsByName("isPassword");
		if(obj.style.display == "none" && objs[0].checked){
			document.getElementById(id).style.display = "block";
		}else if(objs[1].checked){
			document.getElementById(id).style.display = "none";
		}
	}
	
	function showHidden2(id,oldDeptId){
		var obj = document.getElementById(id);
		var curSelectedValue = document.all.deptId.value;
		//var objs = document.getElementsByName("isDept");
		if(obj.style.display == "none" 
			&& curSelectedValue != oldDeptId && curSelectedValue != 0){
			document.getElementById(id).style.display = "block";
		}else if(curSelectedValue == oldDeptId || curSelectedValue == 0){
			document.getElementById(id).style.display = "none";
		}
	}
	
	function update(){
		if(checkForm()){
			document.updateUserForm.action = "./user.do?action=updateUser";
			document.updateUserForm.target = "main";
			//document.updateUserForm.target = "userListFrame";
			document.updateUserForm.submit();
		}
	}
	
	function initPage(result,repeat){
		/**if(result == 1){
			alert("<fmt:message key='common.message.updateSuccess'/>");
		}*/
		if(repeat == 1){
			alert("<fmt:message key='common.message.updateFail'/><fmt:message key='user.lable.userCode'/><fmt:message key='common.message.exist'/>");
		}else if(repeat == 2){
			alert("<fmt:message key='common.message.updateFail'/><fmt:message key='user.lable.userName'/><fmt:message key='common.message.exist'/>");
		}
	}
	
-->
</script>
</head>
<body onload="initPage('${result}','${repeat}')">
<form name="updateUserForm" action="" method="post">
	<table class="table_frame" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table class="table_title" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title_lab" colspan="3">
							&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key="user.title.update"/>
						</td>
					</tr>
					<tr><td height="15"></td></tr>
					<tr>
						<td valign="bottom">&nbsp;
							<a href="javascript:update();" title="<fmt:message key='common.button.save'/>" hidefocus="true"><fmt:message key='common.button.save'/></a>
						</td>
						<td valign="bottom" align="right">
							<a href="javascript:back();" title="返回" hidefocus="true">返回</a>&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="5"></td>
		</tr>
		<tr>
			<td>
				<table class="table1">
					<tr>
						<td>
							<table class="table_input" cellpadding="0" cellspacing="0" style="margin: 0 0 0 100px;">
								<tr><td colspan="2"></td></tr>
								<tr>
									<td width=""><font color="red">用户类别</font><fmt:message key="common.sign"/></td>
									<td>
										<select id="businessStatus" name="businessStatus" style="width: 145px;">
											<option value="0" <c:if test='${user.businessStatus == 0}'>selected</c:if> >业务人员</option>
											<option value="1" <c:if test='${user.businessStatus == 1}'>selected</c:if> >营销管理人员</option>
											<option value="2" <c:if test='${user.businessStatus == 2}'>selected</c:if> >其他人员</option>
										</select>
									</td>
								</tr>
								<tr>
									<td width="15%"><fmt:message key="user.lable.userCode"/><fmt:message key="common.sign"/><input id="id" name="id" type="hidden" value="${user.id}"/></td>
									<td><input id="userCode" name="userCode" class="input_long" type="text" value="${user.userCode}" maxlength="16"/>*</td>
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.userName"/><fmt:message key="common.sign"/></td>
									<td><input id="userName" name="userName" class="input_long" type="text" value="${user.userName}" maxlength="16"/>*</td>
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.deptName"/><fmt:message key="common.sign"/></td>
									<td>
										<select id="deptId" name="deptId" onchange="showHidden2('tUpdateDept','${user.deptId}')">
											<option value="0">----------<fmt:message key="common.select.option"/>----------</option>
											<c:forEach var="dept" items="${depts}">
											<option value="${dept.id}" <c:if test='${user.deptId == dept.id}'>selected</c:if> >${dept.deptName}</option>
											</c:forEach>
										</select>*
									</td>
								</tr>
								<tr id="tUpdateDept" style="display: none;">
									<td width=""><fmt:message key="user.lable.isSaveDept"/><fmt:message key="common.sign"/></td>
									<td>
										<input id="isSaveDept" name="isSaveDept" type="radio" checked="checked" value="0"/><fmt:message key="common.lable.is"/>&nbsp;&nbsp;
										<input id="isSaveDept" name="isSaveDept" type="radio" value="1"/><fmt:message key="common.lable.no"/>
									</td>
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.roleName"/><fmt:message key="common.sign"/></td>
									<td>
										<select id="roleId" name="roleId">
											<option value="0">----------<fmt:message key="common.select.option"/>----------</option>
											<c:forEach var="role" items="${roles}">
											<c:if test="${role.roleCode != 'admin'}">
											<option value="${role.id}" <c:if test='${user.roleId == role.id}'>selected</c:if> >${role.roleName}</option>
											</c:if>
											</c:forEach>
										</select>*
									</td>
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.subPhone"/><fmt:message key="common.sign"/></td>
									<td><input id="subPhone" name="subPhone" class="input_long" type="text" value="${user.subPhone}"/></td>
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.mobile"/><fmt:message key="common.sign"/></td>
									<td><input id="mobile" name="mobile" class="input_long" type="text" value="${user.mobile}"/></td>
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.birthday"/><fmt:message key="common.sign"/></td>
									<td>
										<input id="birthday" name="birthday" class="input_long" type="text" 
											onclick="calendar(this,'yyyy-MM-dd');" readonly="readonly" 
											value="<fmt:formatDate value='${user.birthday}' pattern='yyyy-MM-dd'/>" />
									</td>
								</tr>
								<tr>
									<td width="">Email：</td>
									<td><input id="email" name="email" class="input_long" type="text" value="${user.email}"/></td>
								</tr>
								<tr>
									<td width=""><fmt:message key="common.lable.isActivity"/><fmt:message key="common.sign"/></td>
									<td colspan="3">
										<input name="isActivity" type="radio" <c:if test='${user.isActivity == 1 || user.isActivity == null}'>checked</c:if> value="1"/><fmt:message key="common.lable.is"/>&nbsp;&nbsp;
										<input name="isActivity" type="radio" <c:if test='${user.isActivity == 0}'>checked</c:if> value="0"/><fmt:message key="common.lable.no"/></td>	
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.updatePassword"/><fmt:message key="common.sign"/></td>
									<td colspan="3">
										<input id="isPassword" name="isPassword" type="radio" onclick="showHidden('tPassword')"/><fmt:message key="common.lable.is"/>&nbsp;&nbsp;
										<input id="isPassword" name="isPassword" type="radio" checked="checked" onclick="showHidden('tPassword')"/><fmt:message key="common.lable.no"/></td>	
								</tr>
							</table>
							
							<table id="tPassword" class="table_input" cellpadding="0" cellspacing="0" style="margin: 0 0 0 100px;display: none;">
								<tr>
									<td width="15%"><fmt:message key="user.lable.newPassword"/><fmt:message key="common.sign"/></td>
									<td><input id="password" name="password" class="input_long" type="password" maxlength="16"/></td>
								</tr>
								<tr>
									<td width=""><fmt:message key="user.lable.password2"/><fmt:message key="common.sign"/></td>
									<td><input id="password2" name="password2" class="input_long" type="password" maxlength="16"/></td>
								</tr>
							</table><br>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>	
</body>
</html>